package librecalcdataproxy.ui;

import com.sun.star.frame.DispatchDescriptor;
import com.sun.star.frame.XDispatch;
import com.sun.star.frame.XDispatchProvider;
import com.sun.star.frame.XDispatchProviderInterceptor;
import com.sun.star.uno.XComponentContext;
import com.sun.star.util.URL;
import librecalcdataproxy.server.EventExchanger;

/**
 *
 * @author Wiktor Toporek
 */
public final class DispatchProviderInterceptor implements XDispatchProviderInterceptor { 
    private XDispatchProvider slaveDispatchProvider; 
    private XDispatchProvider masterDispatchProvider; 
    private XComponentContext xContext; 
    EventExchanger ee;
    
    public DispatchProviderInterceptor(final XComponentContext xContext, EventExchanger ee) { 
       this.xContext = xContext; 
       this.ee = ee;
    } 
    public XDispatchProvider getMasterDispatchProvider() { 
       return masterDispatchProvider; 
    } 
    public XDispatchProvider getSlaveDispatchProvider() { 
       return slaveDispatchProvider; 
    } 
    public void setMasterDispatchProvider(final XDispatchProvider arg0) { 
       masterDispatchProvider = arg0; 
    } 
    public void setSlaveDispatchProvider(final XDispatchProvider arg0) { 
       slaveDispatchProvider = arg0; 
    } 

    public XDispatch queryDispatch(final URL arg0, final String arg1, final int arg2) { 
       if(arg0.Complete.equalsIgnoreCase(".uno:LCDPExport")){
           return new ExportEventHandler(xContext, ee);
       }
        
       return getSlaveDispatchProvider().queryDispatch(arg0, arg1, arg2); 
    } 
     
    public XDispatch[] queryDispatches(final DispatchDescriptor[] arg0) { 
       return getSlaveDispatchProvider().queryDispatches(arg0); 
    } 
 }